#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/12/9 10:16
# @Author  : lizhen
# @Site    : 
# @File    : generator.py
# @Software: PyCharm
from collections import Iterator
from inspect import isgeneratorfunction


class CustomGenerator(Iterator):
    def __init__(self, words):
        self.words = words
        self.index = 0

    def __next__(self):
        try:
            word = self.words[self.index]
        except IndexError:
            raise StopIteration
        self.index += 1
        yield word

    def __iter__(self):
        return self


def main():
    cg = CustomGenerator('abc')
    assert isgeneratorfunction(cg.__next__)


if __name__ == '__main__':
    main()
